<?php

load('@.CommonFunc');
include_once APP_PATH.'/vendor/autoload.php';






//KEY=N将数组中某字段列成(1,2,3)样式
//KEY=0将数组中列成(1,2,3)样式
function takearr($arr,$key=null , $tyle = 0){
	$result = $mo = "";
	if(is_array($arr)){

		if(!empty($key)){
			foreach ($arr as $arrkey => $item){
				if($tyle==1){
					if($arr[$arrkey][$key]!='') {
						$result .= $mo . "'" . $arr[$arrkey][$key] . "'";
					}
				}else{
					if($arr[$arrkey][$key]!='') {
						$result .= $mo . $arr[$arrkey][$key];
					}
				}

				$mo = ",";
			}
		}else{
			foreach ($arr as $arrkey => $item){
				if($item == ''){
					continue;
				}
				if($tyle==1){
					$result .= $mo ."'" . $item . "'";
				}else{
					$result .= $mo . $item;
				}

				$mo = ",";
			}
		}

	}
	return "(".$result.")";
}

//加1
function add($a) {
	return $a+1;
}



//字串格式转化
function stringformat($str , $intype = "" , $outtype = ""){
	if(!in_array($intype , array('GBK' , 'UTF-8' , 'GB2312')) || !in_array($outtype , array('GBK' , 'UTF-8' , 'GB2312'))) {
		return $str;
	}
	if(empty($str)) {
		return $str;
	}
	if(is_array($str)){
		foreach ($str as $key=>$value){
			if(is_array($str[$key])){
				$str[$key] = stringformat($str[$key] , $intype , $outtype);
			}else{
				$str[$key] = iconv($intype , $outtype."//IGNORE" , $str[$key]);
			}
		}
	} else {
		$str = iconv($intype , $outtype , $str);
	}
	return $str;
}



//转跳
function jump($url,$str=''){
	global $_CONFIG;
	echo '<script language="javascript">';
	if(trim($str)!=''){
		echo 'alert("'.$str.'");'."\r\n\r\n";
	}
	if($url!=''){
		echo 'window.location.href="'.$url.'";';
	}else{
		echo 'window.history.go(-1);';
	}
	echo '</script>';
	exit();
}

//order_no生成函数
function createOrderNo(){
	$ob = M('csl_temp');
	$data['temp'] = 'T';
	$map = $ob->add($data);
	$ob->delete($map);
	return $map;
}

//打印
function dayin($result) {
	echo "<pre>";
	print_r($result);
	echo "</pre>";
}

//随机字符串
function getRandChar($length){
	$str = '';
	$strPol = "ABCDEFGHJKLMNPQRSTUVWXY0123456789";
	$max = strlen($strPol)-1;
	for($i=0;$i<$length;$i++){
		if($i==0) {
			$str.=$strPol[rand(0,22)];//第一个符号是字母
		}else{
			$str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
		}
	}

	return $str;
}

//手机号码判断
function isTel($tel) {
	$result = preg_match("/^1[0-9]{2}[0-9]{8}$/",$tel);
	return $result?true:false;
}



//手机号审核
function checkmobile($mobile) {
	$db = M("csl_customer");
	$map = array();
	$map['mobile'] = $mobile;
	$result = $db->where($map)->find();
	if(empty($result)) {
		return true;
	}else{
		return false;
	}
}



